<!-- Written by Spike^ekipS <spike_at_gmail.com> -->
{% extends "layout.login" %}

{% block content %}

<table id="table_login" style="">
<form
	onsubmit='

$("input_username").style.borderColor = "gray";
$("input_password").style.borderColor = "gray";

Element.hide("block_login_message");
Element.show("block_start_login");

function checkInputBox (id_input)
{
	var __value = $(id_input).value;
	var __obj_input = $(id_input);
	if (! trimString(__value))
	{
		new Effect.Pulsate(
			id_input,
			{
				duration: 1,
				afterSetup: function(e)
				{
					__obj_input.style.borderColor = "red";
				},
				afterFinish: function(e)
				{
					__obj_input.focus();
				}
			}
		);
		return false;
	}

	return true;
}

if (! checkInputBox("input_username")) return false;
if (! checkInputBox("input_password")) return false;

var __value_username = $("input_username").value;
var __value_password = $("input_password").value;

setTimeout(
	function (e)
	{
		new Ajax.Request(
			"/frontpage/checkLogin/",
			{
				asyncronous: false,
				evalScripts: false,
				parameters: "username=" + encodeURIComponent(__value_username) +
					"&password=" + encodeURIComponent(__value_password),
				/*
				onLoading: function(request)
				{
				},
				*/
				onComplete: function(request)
				{
					Element.hide("block_start_login");

					if (request.status == 200)
					{
						location.href = "/frontpage";
					} else {
						/*
						See project/agu/frontpage/checkLogin/views.py login().
						*/
						switch(request.status)
						{
							case 404 :
								__message = "Enter username or password.";
							break		
							case 405 :
								__message = "\"" + __value_username + "\" does not exist.";
							break
							case 406 :
								__message = "Password does not match.";
							break
						}
						Element.update("block_login_message", __message);
						new Effect.Appear("block_login_message");
					}
				}
			}
		);
	},
	2000
);

return false;
	'
	action="/frontpage/checkLogin" method="POST">
<tr>
	<td align="right">
		Username :
	</td>
	<td>
		<input type="text" id="input_username" name="username" value="">
	</td>
</tr>
<tr>
	<td align="right">
		Password :
	</td>
	<td>
		<input type="password" id="input_password" name="password" value="">
	</td>
</tr>
<tr>
	<td colspan=2 align="right">
		<div
			id="block_login_message"
			style="
				float: left;
				display: none;
				color: orange;
			"
		></div>
		<div
			id="block_start_login"
			style="
				float: left;
				display: none;
			"
		>
			<img src="/__media__/image/running.gif">로그인 중입니다.
		</div>
		<input type="submit" name="submit" value="Login">
	</td>
</tr>
</form>
</table>
{% endblock %}

